$.fn.extend({
	selfupload:function(){
		if($(this).find('img').attr('src') == '')
			$(this).find('img').attr('src','/statics/images/nopic.gif');
		$(this).hover(function(){
			if(!$(this).find('input[type="hidden"]'))
				$(this).append('<input type="hidden" name="pic_url" />');
			_name = typeof($(this).find('input[type="hidden"]').attr('name')) != 'undefined' ? $(this).find('input[type="hidden"]').attr('name') : 'pic_url';
			
			$(this).find('input[type="hidden"]').attr('name',_name);
			itag = typeof($(this).attr('id')) != 'undefined' ? $(this).attr('id') : 'imgbox323';
			_this = $(this);$(this).attr('id',itag);
			var newimg = setInterval(function(){
				if(_this.find('.s_auto').attr('src'))
				{
					window.clearInterval(newimg);
					_this.find('.s_auto').attr('id','');
					setTimeout(_this.selfupload());
				}
			},10);
			var parsrc = _this.find('img').eq(0).attr('src');	
			var w = _this.width();
			var h = _this.height();
			var htm = _this.html();
			_this.css({'overflow':'hidden','position':'relative'});
			var _css = "border:0;z-index:100;position:absolute;overflow:hidden;left:0px;display:none;top:0px;background:rgba(107, 94, 94, 0.24)";
			shtml = '<iframe name="imgobj" id="imgobj" width='+w+' height='+h+' style="'+_css+'" src="http://'+document.domain+'/statics/upload/uploads.php?w='+w+'&h='+h+'&itag='+itag+'&name='+_name+'"></iframe>';
			_this.append(shtml);
			$("#imgobj").hide(1,function(){
				$("#imgobj").fadeIn('slow');
			});
		},function(){
			itag = typeof(_this.attr('id')) != 'undefined' ? _this.attr('id') : 'imgbox323';
			_this.attr('id',itag);
			var son_path = $(window.frames["imgobj"].document).find('#fileval').val();
			if(son_path == '' || typeof(son_path) == 'undefined')
				$('#imgobj').remove();
			else
				_this.unbind('hover');
		})
	},
	selfups:function(){
		_upthis = $(this);
		tId = _upthis.attr('id');
		KindEditor.ready(function(K) {
			var editor = K.editor({
				allowFileManager : true
			});
			
			editor.loadPlugin('image', function() {
				editor.plugin.imageDialog({
					showRemote : false,
					imageUrl : K('.'+tId+'Text').val(),
					clickFn : function(url, title, width, height, border, align) {
						imgUrl = url;
						if(_upthis.attr('tyimg') == 'square' && url){
							// 创建对象
							img = new Image();
							// 改变图片的src
							img.src = url;
							$('.ke-dialog-row').append('<p id="checkmod" style="color:red"><br>&nbsp;&nbsp;正在检测图片合法性..</p>');
							img.onload = function(){
								if(img.width != img.height){
									editor.hideDialog();
									alert('图片规格有误，您上传的图片尺寸 '+img.width+'×'+img.height+'，非正方形规格，请重新上传！');return false;
								}else{
									K('.'+tId+'Text').val(imgUrl);
									editor.hideDialog();
								}
							};
						}else{
							K('.'+tId+'Text').val(url);
							editor.hideDialog();
						}
					}
				});
				$('.ke-dialog-header').html('文件<span class="ke-dialog-icon-close" title="关闭"></span>');
			});
		});
	}
});
$.cookie = function(name, value, options) {
    if (typeof value != 'undefined') {
        options = options || {};
        if (value === null) {
            value = '';
            options.expires = -1;
        }
        var expires = '';
        if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
            var date;
            if (typeof options.expires == 'number') {
                date = new Date();
                date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
            } else {
                date = options.expires;
            }
            expires = '; expires=' + date.toUTCString();
        }
        var path = options.path ? '; path=' + options.path : '';
        var domain = options.domain ? '; domain=' + options.domain : '';
        var secure = options.secure ? '; secure' : '';
        document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
    } else {
        var cookieValue = null;
        if (document.cookie && document.cookie != '') {
            var cookies = document.cookie.split(';');
            for (var i = 0; i < cookies.length; i++) {
                var cookie = jQuery.trim(cookies[i]);
                if (cookie.substring(0, name.length + 1) == (name + '=')) {
                    cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                    break;
                }
            }
        }
        return cookieValue;
    }
};
var opens = function(src,width,height,title,params,bg){
	art.dialog({
	    content: '<div class="loadxxdiv"><img src="/statics/images/ajax_loading.gif" /></div><iframe id="opens" style="padding:0px;border:1px" name="opens" src="'+src+'/ifm/1/'+(params||"")+'" onload="loadit()" width='+(width||800)+' height='+(height||450)+'></iframe>',
	    id: 'TIPCHOSEID',
	    fixed: true,
	    padding: 0,
	    lock: true,
	    title: (title||'新窗口'),
	    background: '#333333',
	    opacity: 0.65,
	    drag: false
	});
	//$('.aui_content').css('background-image', 'url(/statics/images/furley_bg.png)');
}
var showmsg = function(msg,status){
	$('.aui_content').css('background-image', 'false');
	art.dialog({
		icon: status > 0 ? 'succeed' : 'error',
	    fixed: true,
	    content: msg,
	    title: status > 0 ? '成功' : '错误',
	    time: 1
	});
	$('.aui_content').css('background-image', 'false');
	return false;
}
var showimg = function(src){
	art.dialog({
		lock: true,
		fixed: true,
	    padding: 0,
	    title: '查看图片',
	    content: '<img src="'+src+'" />',
	    lock: true
	});
}
var setBtn = function(i){
	i.attr('disabled',true).html('处理中..');
}
var loadit = function(){
	$('.loadxxdiv').remove();
}
$(function(){
	$('img').each(function(){
		if($(this).attr('src') == ''){
			$(this).attr('src','/statics/images/nopic.gif');
		}
	});
	$('.picViews').hover(function(){
		if($(this).attr('url')){
			$(this).css('position','relative');
			$('#picViews').remove();
			var html = '<div style="position:absolute;z-index:1000;right:0px;top:29px;width:250px;height:100px" id="picViews"><a href="'+$(this).attr('url')+'" target="_blank"><img style="width:250px;height:100px" src="'+$(this).attr('url')+'" /></a></div>';
			$(this).append(html);
		}
	},function(){
		$('#picViews').remove();
	});
})
var loadCent = function(per,time){
	$('#loadIngCent').animate({'width':per},time);
}
var jstips = function(tips){
	$.cookie('_sysdomain',tips,{'path':'/','expires':Date.parse(new Date())/1000+10});
	window.location.reload();
}

function GetRequest() { 
	var url = location.search; //获取url中"?"符后的字串 
	var theRequest = new Object(); 
	if (url.indexOf("?") != -1) { 
		var str = url.substr(1); 
		strs = str.split("&"); 
		for(var i = 0; i < strs.length; i ++) { 
			theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]); 
		} 
	} 
	return theRequest; 
} 